/**
 * 
 */
package pl.net.beercrm.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author Rafi
 * 
 */
@Entity(name = "CUSTOMER")
public class Customer {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column(name = "GUID", nullable = false, unique = true, updatable = false, length = 36)
	private String customerId;

	@Column(name = "NAME", nullable = true, length = 30)
	private String name;

	@Column(name = "SURNAME", nullable = true, length = 50)
	private String surname;

	@Temporal(TemporalType.DATE)
	@Column(name = "BIRTHDATE", nullable = true)
	private Date birthDate;

	@Column(name = "REGON", nullable = true, length = 9)
	private String regon;

	@Column(name = "PESEL", nullable = true, length = 11)
	private String pesel;

	@Column(name = "NIP", nullable = true)
	private String nip;

	@Column(name = "COMPANY_NAME", nullable = true, length = 50)
	private String companyName;

	@Column(name = "POSTALCODE", nullable = false, length = 6)
	private String postalCode;

	@Column(name = "STREET", nullable = false, length = 50)
	private String street;

	@Column(name = "CITY", nullable = false, length = 30)
	private String city;

	@Column(name = "STATE", nullable = false, length = 20)
	private String state;

	@Column(name = "PHONE", nullable = true, length = 15)
	private String phone;

	@Column(name = "EMAIL", nullable = false, length = 30)
	private String email;

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "customer")
	private Set<Purchase> purchases = new HashSet<Purchase>(0);

	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	public Long getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname;
	}

	public Set<Purchase> getPurchases() {
		return purchases;
	}

	public void setPurchases(Set<Purchase> purchases) {
		this.purchases = purchases;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public String getRegon() {
		return regon;
	}

	public void setRegon(String regon) {
		this.regon = regon;
	}

	public String getPesel() {
		return pesel;
	}

	public void setPesel(String pesel) {
		this.pesel = pesel;
	}

	public String getNip() {
		return nip;
	}

	public void setNip(String nip) {
		this.nip = nip;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getPostalCode() {
		return postalCode;
	}

	public void setPostalCode(String postalCode) {
		this.postalCode = postalCode;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Customer [customerId=").append(customerId)
				.append(", name=").append(name).append(", surname=")
				.append(surname).append(", birthDate=").append(birthDate)
				.append(", regon=").append(regon).append(", pesel=")
				.append(pesel).append(", nip=").append(nip)
				.append(", companyName=").append(companyName)
				.append(", postalCode=").append(postalCode).append(", street=")
				.append(street).append(", city=").append(city)
				.append(", state=").append(state).append(", phone=")
				.append(phone).append(", email=").append(email).append("]");
		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((birthDate == null) ? 0 : birthDate.hashCode());
		result = prime * result + ((city == null) ? 0 : city.hashCode());
		result = prime * result
				+ ((customerId == null) ? 0 : customerId.hashCode());
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((pesel == null) ? 0 : pesel.hashCode());
		result = prime * result + ((phone == null) ? 0 : phone.hashCode());
		result = prime * result
				+ ((postalCode == null) ? 0 : postalCode.hashCode());
		result = prime * result + ((regon == null) ? 0 : regon.hashCode());
		result = prime * result + ((state == null) ? 0 : state.hashCode());
		result = prime * result + ((street == null) ? 0 : street.hashCode());
		result = prime * result + ((surname == null) ? 0 : surname.hashCode());
		result = prime * result + ((nip == null) ? 0 : nip.hashCode());
		result = prime * result
				+ ((companyName == null) ? 0 : companyName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Customer other = (Customer) obj;
		if (customerId == null) {
			if (other.customerId != null)
				return false;
		} else if (!customerId.equals(other.customerId))
			return false;
		return true;
	}
}
